
******************************************************************************
* Combine the files
******************************************************************************

***** FOMC meeting information
use "data/fomc_dates/clean_data/FOMC_meeting_dates.dta", clear

**** Kuttner monetary policy shock
preserve 
	use "data/kuttner_shocks/clean_data/kuttner_shocks.dta", clear
	tempfile kuttner_shocks
	save	`kuttner_shocks'
restore 
merge 1:1 date using `kuttner_shocks', nogen
sort date

***** Dot plot
preserve 
	use "data/dotplot/clean_data/dotplot.dta", clear
	
	*Generate change in long-run dot plot
	sort date
	generate dotlr_chg = dotlr - dotlr[_n-1] 
	
	*Generate 1-year dot plot and change in 1-year dot plot
	generate dot1y = .
	generate dot1y_chg = . 
	forvalues year = 2012/2021 {
		display "`year'"	
		*1year forecast
		local yearplus1 = `year' + 1
		capture replace dot1y_chg = dot`yearplus1' - dot`yearplus1'[_n-1] if year == `year'
		capture replace dot1y = dot`yearplus1' if year == `year'
	}	
	
	keep date dotlr dotlr_chg dot1y dot1y_chg
	
	tempfile dotplot 
	save	`dotplot'
restore 
merge 1:1 date using `dotplot', nogen
sort date

**** SEP long-run inflation projections
preserve 
	use "data/fred/clean_data/inflation_projections.dta", clear
	
	*Date filter
	keep if date < td(01jul2021)
	keep if date >= td(01jan2012) //Focus on the dot plot period
	
	tempfile inflation_projections
	save	`inflation_projections'
restore 
merge 1:1 date using `inflation_projections', nogen
sort date

***** Treasurys from Fed website
preserve 
	use "data/gsw_treasurys/clean_data/gsw_treasurys.dta", clear

	keep if date >= td(01jan1980)
	keep if date <= td(30jun2021)
	
	tempfile treasurys
	save	`treasurys'
restore 
merge 1:1 date using `treasurys', nogen

***** TIPS from Fed website
preserve 
	use "data/gsw_tips/clean_data/gsw_tips.dta", clear

	keep if date >= td(01jan1980)
	keep if date <= td(30jun2021)
	
	tempfile tips
	save	`tips'
restore 
merge 1:1 date using `tips', nogen
sort date

***** Bloomberg data 
preserve 
	use "data/bloomberg/clean_data/bloomberg.dta", clear

	keep if date >= td(01jan1980)
	keep if date <= td(30jun2021)
	
	*Generate one-month S&P 500 returns
	tsset date	
	generate spx_logret = log(1+spx_ret/100)
	tsegen spx_logret1m = rowtotal(L(0/30).spx_logret)
	drop spx_logret spx_ret
	
	tempfile bloomberg
	save	`bloomberg'
restore 
merge 1:1 date using `bloomberg', nogen
sort date

***** VIX 
preserve 
	use "data/vix/clean_data/vix.dta", clear
	
	keep if date >= td(01jan1980)
	keep if date <= td(30jun2021)
	
	tempfile vix 
	save	`vix'
restore 
merge 1:1 date using `vix', nogen
sort date

**** Fred
	//NBER recession indicator
	//Treasury slope
	//Chicago Fed National Activity Index
	//Brave-Butters-Kelley leading index
preserve 
	use "data/fred/clean_data/all_variables.dta", clear	

	keep if date >= td(01jan1980)
	keep if date <= td(30jun2021)
	
	tempfile fred_data
	save	`fred_data'
restore 
merge 1:1 date using `fred_data', keep(1 3) nogen
sort date

***** Nonfarm payrolls 
preserve 
	use "data/nonfarm_payrolls/clean_data/nonfarm_payrolls.dta", clear

	keep if date >= td(01jan1980)
	keep if date <= td(30jun2021)
	
	tempfile nonfarm_payrolls
	save	`nonfarm_payrolls'
restore 
merge 1:1 date using `nonfarm_payrolls', keep(1 3) nogen
sort date
	
***** Construct yield changes
sort date	
local yield_list "svenf05 svenf09 sveny01 sveny02 sveny05 sveny10 sveny30 fwd5y5y bkeven10 tipsy10 tipsy20 tips5y5y usgg10 usgg5 usgg30 gtii10 gtii30 usswit10"
foreach x of local yield_list{

	generate `x'_chg = `x' - `x'[_n-1]
	replace `x'_chg = `x' - `x'[_n-2] if missing(`x'_chg)
	replace `x'_chg = `x' - `x'[_n-3] if missing(`x'_chg)
	replace `x'_chg = `x' - `x'[_n-4] if missing(`x'_chg)
	replace `x'_chg = `x' - `x'[_n-5] if missing(`x'_chg)
	replace `x'_chg = `x' - `x'[_n-6] if missing(`x'_chg)
	replace `x'_chg = `x' - `x'[_n-7] if missing(`x'_chg)
}	

*Make time-series data set
tsset date

label variable dotlr_chg 	"Change in the long-run dot"
label variable dot1y 		"Dot plot: fed funds rate at YE of the next year"
label variable dot1y_chg 	"Change in 1yr dot"
label variable spx_logret1m "S&P 500 1m log returns"

foreach x of local yield_list{
		local base_label : variable label `x'
		local new_label  "Change in `base_label'"
		label variable `x'_chg "`new_label'"
}
	
compress
save "data/final_data_fed_secular_decline.dta", replace 	
